﻿@model OKRs.Models.ObjectiveViewModels.UpdateObjectiveViewModel

@{
    ViewData["Title"] = "Edit Objective";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<ol class="breadcrumb">
    <li><a asp-controller="Home" asp-action="Index">Home</a></li>
    <li><a asp-controller="Objective" asp-action="Index">Objectives</a></li>
    <li><a asp-controller="Objective" asp-action="Details" asp-route-id="@Model.Id">@Model.Title</a></li>
</ol>

<h3>Edit Objective</h3>

<div class="row">
    <div class="col-md-4">
        <form asp-action="Edit" method="POST" asp-route-id="@Model.Id">
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <div class="form-group">
                <label asp-for="Title" class="control-label"></label>
                <input asp-for="Title" class="form-control" />
                <span asp-validation-for="Title" class="text-danger"></span>
            </div>
            <div class="form-group">
                <input type="submit" value="Save" class="btn btn-primary" />
                <input type="button" id="delete-button" value="Delete" class="btn btn-danger" />
            </div>
        </form>
    </div>
</div>

@section Scripts {
    <script type="application/javascript">
    $('#delete-button').one('click', function(e){
        $.ajax({
            url: '@OKRs.Extensions.UrlHelperExtensions.AbsoluteAction(Url, "Delete", "Objective", new { id = Model.Id })',
            method: "DELETE"
        }).done(function() {
            location.href = '@OKRs.Extensions.UrlHelperExtensions.AbsoluteAction(Url, "Index", "Objective")';
        })
    });
    </script>
}